home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Internet / HTML NS to WS < prev    next >
Encoding:
Text File  |  1999-03-04  |  4.3 KB  |  195 lines  |  [TEXT/ToyS]

  1. -- Preferences
  2. property kasPrefName : "NetScape to WebStar SSI"
  3.  
  4. property kasWebStarSSI : "<!--#include virtual="
  5. property kasNetScapeSSI : "<!--#include file="
  6.  
  7. property kasTypesToDo : {"TEXT"} -- Only run on these types
  8. property kasExtToDo : "" -- Use non-empty match string (e.g. "*.html") to limit to that extension
  9.  
  10. -- Globals
  11. global gasInfoWind -- Info window
  12. global gasInfoPos -- Position of info window
  13. global gasFoldersToDo -- The folders left to process
  14. global gasConverted -- Number gone!
  15. global gasChecked -- Number checked!
  16. global gasPrefix -- Adjusted kasPrefix (munge the % parms)
  17.  
  18.  
  19. on open fsObjs
  20.     -- Load prefs, show window
  21.     pfLoad()
  22.     
  23.     set gasConverted to 0
  24.     set gasChecked to 0
  25.     
  26.     set gasInfoWind to display info titled kasPrefName ¬
  27.         located at gasInfoPos ¬
  28.         message "Scanning…"
  29.     
  30.     -- Do files
  31.     set gasFoldersToDo to {}
  32.     
  33.     repeat with fsObj in fsObjs
  34.         set myInfo to (basic info for fsObj)
  35.         
  36.         if (system type of myInfo is "fold") then
  37.             set gasFoldersToDo to gasFoldersToDo & {fsObj}
  38.         else if (system type of myInfo is in kasTypesToDo) then
  39.             if (kasExtToDo is "") or ((collect lines of (catalog name of myInfo) that match kasExtToDo) is not "") then
  40.                 DoOne(fsObj)
  41.             end if
  42.         end if
  43.     end repeat
  44.     
  45.     -- Do folders
  46.     repeat while gasFoldersToDo is not {}
  47.         -- Pop one off the end
  48.         set n to the number of items of gasFoldersToDo
  49.         set fsObj to item n of gasFoldersToDo
  50.         
  51.         if (n > 1) then
  52.             set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
  53.         else
  54.             set gasFoldersToDo to {}
  55.         end if
  56.         
  57.         display info gasInfoWind ¬
  58.             message ("Folders to go: " & n) ¬
  59.             at line 6 ¬
  60.             using color (15 * 32)
  61.         
  62.         -- Process it
  63.         GoDeep(fsObj)
  64.     end repeat
  65.     
  66.     display info gasInfoWind message "DONE!"
  67.     
  68.     pause for 5 with seconds timing -- Let screen wait...
  69.     
  70.     set gasInfoPos to screen location of ¬
  71.         (display info gasInfoWind with disposal)
  72.     
  73.     pfSave() -- Save window location
  74. end open
  75.  
  76.  
  77. on DoOne(fsObj)
  78.     set aFileInfo to (alias info from fsObj)
  79.     
  80.     display info gasInfoWind ¬
  81.         message "File: " & (original name of aFileInfo) ¬
  82.         at line 2
  83.     
  84.     set gasChecked to gasChecked + 1
  85.     
  86.     display info gasInfoWind ¬
  87.         message ("Checked: " & gasChecked) ¬
  88.         at line 7 ¬
  89.         using color 15
  90.     
  91.     ConvertFile(fsObj)
  92. end DoOne
  93.  
  94.  
  95. on ConvertFile(fsObj)
  96.     try
  97.         set fileRef to ¬
  98.             open fork from fsObj ¬
  99.                 with write access
  100.     on error errStr
  101.         display info gasInfoWind ¬
  102.             message ("Error: " & errStr) ¬
  103.             at line 12 ¬
  104.             using color (25 * 1024)
  105.         return
  106.     end try
  107.     
  108.     set fname to catalog name of (basic info for fsObj)
  109.     
  110.     set fileData to read data from fileRef
  111.     set newData to fileData
  112.     
  113.     -- Convert SSI!
  114.     set newData to munge newData ¬
  115.         searching for kasNetScapeSSI ¬
  116.         replacing it with kasWebStarSSI
  117.     
  118.     -- Rename to lowercase?
  119.     if (not (the same data is in fileData given «class Cmp≈»:newData)) then
  120.         -- Reset file to 0 long
  121.         size fork fileRef given «class len »:0
  122.         -- Write data
  123.         write data to fileRef from buffer newData
  124.         
  125.         set gasConverted to gasConverted + 1
  126.         
  127.         display info gasInfoWind ¬
  128.             message ("Converted: " & gasConverted) ¬
  129.             at line 8 ¬
  130.             using color (15 * 1024)
  131.         display info gasInfoWind ¬
  132.             message ("Last: " & fname) ¬
  133.             at line 9 ¬
  134.             using color (16 * 1024)
  135.     end if
  136.     
  137.     close fork fileRef
  138. end ConvertFile
  139.  
  140.  
  141.  
  142. on GoDeep(foldObj)
  143.     display info gasInfoWind ¬
  144.         message "Path: " & (foldObj as string)
  145.     
  146.     set daddy to foldObj as string
  147.     
  148.     -- Do kinds that match
  149.     display info gasInfoWind ¬
  150.         message "Scanning files" at line 5
  151.     
  152.     if (kasExtToDo is "") then
  153.         set myItems to the entries in foldObj ¬
  154.             whose types are in kasTypesToDo
  155.     else
  156.         set myItems to the entries in foldObj ¬
  157.             whose types are in kasTypesToDo ¬
  158.             whose names match kasExtToDo
  159.     end if
  160.     
  161.     repeat with myItem in myItems
  162.         DoOne((daddy & myItem) as alias)
  163.     end repeat
  164.     
  165.     -- Do folders
  166.     display info gasInfoWind ¬
  167.         message "Scanning subfolders" at line 5
  168.     
  169.     set myItems to the entries in foldObj ¬
  170.         whose kinds are a folder
  171.     
  172.     repeat with myItem in myItems
  173.         set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
  174.     end repeat
  175.     
  176.     -- Done
  177.     display info gasInfoWind ¬
  178.         message "…" at line 5
  179. end GoDeep
  180.  
  181.  
  182. on pfLoad()
  183.     try
  184.         set ourPrefs to (load preference named kasPrefName)
  185.         set gasInfoPos to item 1 of ourPrefs
  186.     on error
  187.         set gasInfoPos to {0, 0}
  188.     end try
  189. end pfLoad
  190.  
  191.  
  192. on pfSave()
  193.     save preference {gasInfoPos} named kasPrefName
  194. end pfSave
  195.